#include <iostream>
#include <nlohmann/json.hpp>
#include <fstream>

using json = nlohmann::json;

int main() {
    // 测试1：创建 JSON 对象并序列化
    json j;
    j["name"] = "Alice";
    j["age"] = 30;
    j["skills"] = {"C++", "Python"};
    std::cout << "Serialized JSON: " << j.dump(2) << "\n\n";

    // 测试2：解析字符串
    std::string json_str = R"({"project": "nlohmann-json", "version": "3.7.3"})";
    auto j2 = json::parse(json_str);
    std::cout << "Parsed value: " << j2["project"] << " (version " << j2["version"] << ")\n\n";

    // 测试3：文件读写
    std::ofstream("test.json") << j.dump(2);  // 写入文件
    std::ifstream in("test.json");
    json j3;
    in >> j3;  // 读取文件
    std::cout << "Read from file: " << j3.dump(4) << "\n\n";


    return 0;
}
